package testing;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.*;
import Background.Contestant;
import Background.Lists;
/**
* Test cases for adding and reading in a existing file of contestants.
* @author Justin Wong.
*
*/
public class TestingJustbeweave {
/**
* Lists to be tested.
*/
private Lists MY_LIST;
/**
* Strings for getting direct path from different computers.
*/
private String MY_USER_HOMEFOLDER;
/**
* Strings for getting direct path from different computers.
*/
private String MY_FILE_SEPERATOR;
/**
* Strings for getting direct path from different computers.
*/
private File MY_CONTESTANT_FILE;
private File MY_JUDGE_FILE;
private List MY_CONTESTANT_LIST;
private Contestant c1;
private Contestant c2;
private Contestant c3;
/**
* Initializes all the necessary fields before proceeding to testing.
* @author Justin Wong
* @throws IOException
*/
@Before
public void initilize() throws IOException{
MY_LIST = new Lists();
Lists.readData();
MY_USER_HOMEFOLDER = System.getProperty("user.home");
MY_FILE_SEPERATOR = System.getProperty("file.separator");
MY_CONTESTANT_FILE = new File(MY_USER_HOMEFOLDER + MY_FILE_SEPERATOR + "Desktop" + MY_FILE_SEPERATOR + "contestant.txt");
MY_JUDGE_FILE = new File(MY_USER_HOMEFOLDER + MY_FILE_SEPERATOR + "Desktop" + MY_FILE_SEPERATOR + "judge.txt");
MY_CONTESTANT_LIST = Lists.getContestantList();
c1 = (Contestant) MY_CONTESTANT_LIST.get(0);
c2 = (Contestant) MY_CONTESTANT_LIST.get(1);
Lists.addContestant(new Contestant("chris petcher", "chrispetcher@gmail.com", "false", "chrispetcher",
"chrispetcher", "555-555-5555", 0));
c3 = (Contestant) MY_CONTESTANT_LIST.get(2);
}
/**
* Test to determine if file exist. Which should be true since if file contestant.txt
* or judge.txt doesn't exist, it will be created on the desktop.
* @author Justin Wong
*/
@Test
public void testFileExist() {
assertTrue(MY_CONTESTANT_FILE.exists());
assertTrue(MY_JUDGE_FILE.exists());
}
/**
* Test the import of the contestant.txt file to determine if the information is the same.
* @author Justin Wong
*/
@Test
public void testExistingContestants(){
assertEquals("justin wong", c1.getName());
assertEquals("justinwong@gmail.com", c1.getEmail());
assertEquals("justinwong", c1.getUserName());
assertEquals("justinwong", c1.getPassword());
assertEquals("222-222-2222", c1.getPhoneNumber());
assertEquals("justin sorrel", c2.getName());
assertEquals("justinsorrel@gmail.com", c2.getEmail());
assertEquals("justinsorrel", c2.getUserName());
assertEquals("justinsorrel", c2.getPassword());
assertEquals("333-333-3333", c2.getPhoneNumber());
}
/**
* Test to determine adding a new contestant to the list, they should exist.
* @author Justin Wong
*/
@Test
public void addingContestant(){
assertEquals("chris petcher", c3.getName());
assertEquals("chrispetcher@gmail.com", c3.getEmail());
assertEquals("chrispetcher", c3.getUserName());
assertEquals("chrispetcher", c3.getPassword());
assertEquals("555-555-5555", c3.getPhoneNumber());
}
}